<!-- 公司破底价审核 -->
<template>
  <div class='base_price_audit'>
    <dt-search ref="search"></dt-search>
    <Tabs v-model="curState" type="card" :animated="false" @on-click="onChangeTab">
      <TabPane label="待审核" name="0"></TabPane>
      <TabPane label="已通过" name="1"></TabPane>
      <TabPane label="已驳回" name="2"></TabPane>
    </Tabs>
    <dt-grid ref="table" page :onFetch='onFetch' />
    <detail-modal ref="detailModal" :isCompanyBase=true @success='success' />
  </div>
</template>

<script>
  import searchOpt from './opt/search'
  import Column from './opt/columns'
  import auditMgr from '@/biz/flowApproval/processAudit.js'
  import detailModal from '../../casemanagement/flowApproval/basePrice/components/detailModal.vue'

  export default {
    components: { detailModal },
    data() {
      return {
        curState: '0',
        oldState: '0',
        formValidate: {
          orgId: [],
          housesId: ''
        },
      };
    },
    methods: {
      onChangeTab(val) {
        if (val == this.oldState) return false
        this.oldState = val
        this.$refs.table.init(this, new Column(this))
        this.$refs.table.fetch()
      },
      onFetch(data) {
        return auditMgr.list({
          ...data,
          auditType: 9,
          buttonType: this.curState
        }).then(res => {
          res && res.list.forEach(item => {
            item = Object.assign(item, item.auditData)
          })
          return res
        })
      },
      init() {
        this.$refs.search.init(this.$refs.table, new searchOpt(this).options(), this
          .formValidate)
        this.$refs.table.init(this, new Column(this))
        this.$refs.table.fetch()
      },
      auditFun(data) {
        console.log(data)
        data.title = '审核'
        data.flag = 'audit'
        this.$refs.detailModal.show(data)
      },
      viewFun(data) {
        data.title = '查看'
        data.flag = 'check'
        this.$refs.detailModal.show(data)
      },
      success() {
        this.$refs.table.fetch()
      }
    },
    mounted() {
      this.init()
    }
  }
</script>
<style lang='scss' scoped>
  .base_price_audit {
    padding: 20px;
  }
</style>